package versionControl.aspectj.test;

//import versionControl.aspectj.library.RollbackSystemException;

@SuppressWarnings("serial")
public class ObjectVersionControlChecker
{
	public Integer field1;
    private Integer maxValue;
    
    public ObjectVersionControlChecker()
    {
            field1 = new Integer(0);
            maxValue = 150;
    }
    
    public ObjectVersionControlChecker(int init)
    {
            field1 = init;
            maxValue = 150;
    }
    
    public void setField(Integer other)
    {
        field1 = other;
    }
    
    public Integer getField()
    {
            return field1;
    }
    
    public void validate() throws UnSupportedField
    {
            if (field1 > maxValue)
                    throw new UnSupportedField();
    }
        
    public String toString()
    {
    	return (new String(" field: " + this.field1));
    }
    /*public static void rollbackAllCheck() throws RollbackSystemException
    {
    	throw new RollbackSystemException();
    }*/
    
    public void enterSandbox()
    {
    	System.out.println("in sandbox");
    }
    
    public void exitSandbox()
    {
    	System.out.println("exit sandbox");
    }
    
    public static void main(String[] args){
	    ObjectVersionControlChecker test = new ObjectVersionControlChecker();	    
	    ObjectVersionControlChecker test1 = new ObjectVersionControlChecker(100);
	    
	    try{
	    test.setField(new Integer(4));
	    }catch(Exception e){
	    	e.printStackTrace();
	    }
	              
	    test1.setField(200);            
	    try
	    {
	            test1.validate();
	    }catch(UnSupportedField e){}
	    test1.setField(140);
	    
	    test.setField(new Integer(2));
	    test.setField(new Integer(5));
	    test.setField(new Integer(0));
	    try{
	    	//ObjectVersionControlChecker.rollbackAllCheck();
	    }catch(Exception e){System.out.println("Catch rollbackSystemException");}
	    test1.enterSandbox();
	    test.setField(new Integer(1));
	    test1.setField(201);
	    test1.exitSandbox();
	    test1.setField(202);
    }
}